package com.zbkj.admin.controller.merchant;

import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.water.RzPackageRequest;
import com.zbkj.common.request.water.SearchRzPackageRequest;
import com.zbkj.common.response.water.RzPackageResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.water.RzPackageService;
import io.micrometer.core.instrument.search.Search;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("api/admin/merchant/package")
@Api(tags = "平台套餐管理控制器")
public class RzPackageController {

    @Autowired
    private RzPackageService rzPackageService;

    @ApiOperation(value = "添加修改套餐")
    @PostMapping("/saveOrUpdatePackage")
    public CommonResult<Object> saveOrUpdatePackage(@RequestBody @Validated RzPackageRequest request) {
        if(rzPackageService.saveOrUpdatePackage(request)){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation(value = "删除套餐")
    @GetMapping("/deletePackage/{id}")
    public CommonResult<Object> deletePackage(@PathVariable Integer id) {
        if(rzPackageService.deletePackage(id)){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation(value = "套餐分页列表")
    @PostMapping("/getPackageList")
    public CommonResult<CommonPage<RzPackageResponse>> getPackageList(@RequestBody @Validated SearchRzPackageRequest request) {
        return CommonResult.success(rzPackageService.getPackageList(request));
    }
}
